package pikes.ecma;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import pikes.ecma.VariableStatement;

public class VariableStatementTestCase {

	private MockSyntaxTreeVisitor syntaxTreeVisitor = null;

	private StringBuilder appendable = null;

	@Before
	public void setup() {
		appendable = new StringBuilder();
		syntaxTreeVisitor = new MockSyntaxTreeVisitor();
	}

	@Test
	public void printVariableStatement() throws Exception {
		VariableStatement vs = new VariableStatement("url");
		vs.print(appendable);

		Assert.assertEquals("var url;", appendable.toString());

	}

	@Test
	public void visitVariableStatement() throws Exception {
		VariableStatement vs = new VariableStatement("url");
		vs.visit(syntaxTreeVisitor);

		Assert.assertTrue(syntaxTreeVisitor.isBeforeVariableDeclaration);
		Assert.assertTrue(syntaxTreeVisitor.identifier.equals("url"));
		Assert.assertTrue(syntaxTreeVisitor.isEndOfStatement);
	}

	@Test
	public void visitVariableStatementWithAssignmentExpression() throws Exception {
		MockIExpression expression = new MockIExpression();
		VariableStatement vs = new VariableStatement("url", expression);
		vs.visit(syntaxTreeVisitor);

		Assert.assertTrue(syntaxTreeVisitor.isBeforeVariableDeclaration);
		Assert.assertTrue(syntaxTreeVisitor.identifier.equals("url"));
		Assert.assertTrue(syntaxTreeVisitor.isEqualSign);
		Assert.assertSame(syntaxTreeVisitor, expression.syntaxTreeVisitor);
		Assert.assertTrue(syntaxTreeVisitor.isEndOfStatement);

	}
}
